﻿<Window x:Class="MoPlus.SolutionBuilder.WpfClient.UserControls.Interpreter.CodeTemplateContentDialog"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:mod="clr-namespace:MoPlus.Interpreter.BLL.Interpreter;assembly=MoPlus.Interpreter"
			 xmlns:ir="clr-namespace:Irony.Interpreter.Ast;assembly=Irony"
			 xmlns:lib="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library" Topmost="True"
             xmlns:Settings="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library;assembly=MoPlus.SolutionBuilder.WpfClient"
             Title="{Binding WindowCaption}" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="200">
	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="../../Resources/Theme.xaml" />
			</ResourceDictionary.MergedDictionaries>
			<BitmapImage x:Key="Icon_TreeOpen"   UriSource="../../Resources/Images/NodeOpen.png"   />
			<BitmapImage x:Key="Icon_TreeClosed" UriSource="../../Resources/Images/Node.png" />
			<Style x:Key="IconImageStyleSmall" TargetType="Image">
				<Setter Property="MaxWidth" Value="16"/>
				<Setter Property="MaxHeight" Value="16"/>
				<Setter Property="Margin" Value="0,0,0,0"/>
			</Style>
			<Style x:Key="TreeViewItemTextStyle" TargetType="{x:Type TextBlock}">
				<Setter Property="Text" Value="{Binding DisplayName, Mode=OneWay}" />
				<Setter Property="Foreground" Value="Black" />
				<Setter Property="Padding" Value="5,0,4,0" />
				<Setter Property="Margin" Value="0" />
			</Style>
			<!-- leaf node -->
			<DataTemplate DataType="{x:Type mod:LeafGrammarNode}">
				<StackPanel Orientation="Horizontal">
					<Image x:Name="nodeImg" Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_TreeClosed}" />
					<TextBlock Style="{DynamicResource TreeViewItemTextStyle}"/>
				</StackPanel>
			</DataTemplate>
			<!-- non leaf node -->
			<HierarchicalDataTemplate DataType="{x:Type mod:NonLeafGrammarNode}" ItemsSource="{Binding ChildNodes, Mode=OneWay}">
				<StackPanel Orientation="Horizontal">
					<Image x:Name="nodeImg" Style="{StaticResource IconImageStyleSmall}" Source="{StaticResource Icon_TreeClosed}" />
					<TextBlock Style="{DynamicResource TreeViewItemTextStyle}"/>
				</StackPanel>
				<HierarchicalDataTemplate.Triggers>
					<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=lib:ModelTreeViewItem}, Path=IsExpanded}" Value="True">
						<Setter TargetName="nodeImg" Property="Source" Value="{Binding Source={StaticResource Icon_TreeOpen}, Mode=OneTime}"/>
					</DataTrigger>
				</HierarchicalDataTemplate.Triggers>
			</HierarchicalDataTemplate>
		</ResourceDictionary>
	</Window.Resources>
	<Grid MaxWidth="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=ScrollViewer}}" MaxHeight="{Binding ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=ScrollViewer}}" RenderTransformOrigin="0.5,0.5">
		<Grid.LayoutTransform>
			<TransformGroup>
				<ScaleTransform ScaleX="{Binding Source={x:Static Settings:UserSettingsHelper.Instance}, Path=ControlSize, Mode=TwoWay}"
					                ScaleY="{Binding Source={x:Static Settings:UserSettingsHelper.Instance}, Path=ControlSize, Mode=TwoWay}"/>
			</TransformGroup>
		</Grid.LayoutTransform>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"></RowDefinition>
			<RowDefinition Height="*"></RowDefinition>
			<RowDefinition Height="Auto"></RowDefinition>
		</Grid.RowDefinitions>
		<Label Margin="1" Grid.Row="0" Style="{DynamicResource LabelHeader}" Content="{Binding Title, Mode=OneWay}" />
		<TabControl Grid.Row="1" TabStripPlacement="Left">
			<TabItem Header="{Binding ResultsASTLabel}" IsSelected="False" Style="{DynamicResource FixedTabItem}">
				<GroupBox Grid.Row="1" Header="{Binding ResultsASTLabel}">
					<lib:ModelTreeView DataContext="{Binding ResultsAST}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding ChildNodes, Mode=OneWay}"/>
				</GroupBox>
			</TabItem>
			<TabItem Header="{Binding SampleCodeLabel}" IsSelected="True" Style="{DynamicResource FixedTabItem}">
				<GroupBox Grid.Row="2" Header="{Binding SampleCodeLabel}">
					<TextBox IsReadOnly="True" Text="{Binding SampleCode, Mode=OneWay}" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"/>
				</GroupBox>
			</TabItem>
		</TabControl>
		<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="2">
			<Button Padding="10,5,10,5" Command="{Binding CloseCommand}" Content="{Binding OKButtonLabel}"></Button>
		</StackPanel>
	</Grid>
</Window>
